/**
 * Bestpay.com.cn Inc.
 * Copyright (c) 2011-2020 All Rights Reserved.
 */
package com.suxiaoxiao.springbootlearn.designpattern.templatepattern;

import com.suxiaoxiao.springbootlearn.designpattern.templatepattern.hookdemo.CoffeeWithHook;
import com.suxiaoxiao.springbootlearn.designpattern.templatepattern.hookdemo.TeaWithHook;
import com.suxiaoxiao.springbootlearn.designpattern.templatepattern.jdk.Duck;
import org.junit.jupiter.api.Test;

import java.util.Arrays;

/**
 * 模板方法测试
 * 钩子
 *
 * @author zhaorongzhang
 * @version BeverageTestDrive.java, v 0.1 2020/1/4 4:01 下午 zhaorongzhang Exp $$
 */
public class BeverageTestDrive {

    @Test
    public void test_template_pattern_with_hook() {
        TeaWithHook teaWithHook = new TeaWithHook();
        CoffeeWithHook coffeeWithHook = new CoffeeWithHook();

        System.out.println("\nMaking tea...");
        teaWithHook.prepareRecipe();
        System.out.println("\nMaking coffee...");
        coffeeWithHook.prepareRecipe();
    }

    @Test
    public void test_template_pattern_with_jdk_comparable() {
        Duck[] ducks = {
                new Duck("Daffy", 8),
                new Duck("Dewey", 2),
                new Duck("Howard", 7),
                new Duck("Louie", 2),
                new Duck("Donald", 10),
                new Duck("Huey", 2)
        };
        System.out.println("Before sorting...");
        display(ducks);
        Arrays.sort(ducks);

        System.out.println("\n After sorting...");
        display(ducks);
    }

    private void display(Duck[] ducks) {
        for (Duck duck : ducks) {
            System.out.println(duck);
        }
    }

}